<?php
/**
 * SocialEngine
 *
 * @category   Application_Core
 * @package    Messages
 * @copyright  Copyright 2006-2010 Webligo Developments
 * @license    http://www.socialengine.net/license/
 * @version    $Id: Controller.php 9308 2011-09-22 00:36:41Z john $
 * @author     John Boehr <j@webligo.com>
 */

/**
 * @category   Application_Core
 * @package    User
 * @copyright  Copyright 2006-2010 Webligo Developments
 * @license    http://www.socialengine.net/license/
 */
class Visits_Widget_ProfileWhoIViewedController extends Engine_Content_Widget_Abstract
{
  public function indexAction()
  {

    // Just remove the title decorator
    $this->getElement()->removeDecorator('Title');
    
    // Get viewer
    $viewer = Engine_Api::_()->user()->getViewer();
    
    // check auth
    if( !Engine_Api::_()->authorization()->isAllowed('visits', $viewer, 'view') ) {
      return $this->setNoRender();
    }
      
    // Get page
    $page = $this->_getParam('page');
    
    // Get subject
    if($this->_getParam('subject'))
    $subject = Engine_Api::_()->getItemByGuid($this->_getParam('subject'));
    else
    $subject = Engine_Api::_()->core()->getSubject();
    
    // Get visits of subject
    $this->view->visits = $visits = Engine_Api::_()->getDbtable('visits', 'visits')->getVisitsByMe($subject);
    $visits->setItemCountPerPage($this->_getParam('itemCountPerPage', 6));
    $visits->setCurrentPageNumber($this->_getParam('page', 1));
    
    // Do not render if nothing to show
    if( $visits->getTotalItemCount() <= 0 ) {
      return $this->setNoRender();
    }
      
  }
}
